<#include "/template/_ListPageWithTree.html" /> <#assign
left_title="部门列表"> <@left>
<ul id="lefttree" class="easyui-tree" url="${root!}/framedept/leftTree"></ul>
<script type="text/javascript">
	$(function() {
		$('#lefttree').tree({
			onClick : function(node) {
				$('#dg').datagrid({
					url : '${root!}/frameuser/table?code=' + node.attributes.deptCode
				});
			}
		});
	});
</script>
</@left> <@center>


<div class="easyui-layout" fit="true">
	<div region="north" style="height: 65px;">

		<div style="margin-bottom: 5px; border-bottom: 1px solid #ddd;">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
				onclick="addUser();">新增用户</a> <a href="#" class="easyui-linkbutton"
				onclick="deleteUser()"
				data-options="plain:true,iconCls:'icon-cancel'">删除选中</a> <a href="#"
				class="easyui-linkbutton" onclick="ResetPass()"
				data-options="plain:true,iconCls:'icon-redo'">重置密码</a>
		</div>
		<div>
			登录名: <input class="easyui-box" style="width: 80px" id="inpUsername">
			显示名: <input class="easyui-box" style="width: 80px"
				id="inpDisplayname"> <a href="#" class="easyui-linkbutton"
				iconCls="icon-search" onclick="searchUser()">查询</a>
		</div>


	</div>


	<div region="center" title="用户信息">

		<div id="cc" class="easyui-layout" fit="true">
			<div region="center" style="padding: 0px; background: #eee;"
				split="false">

				<@datatable toolbar="#tb" id="dg" model="${root!}/frameuser/table" fit="true" onLoadSuccess="function() {$('#dg').datagrid('selectRow', 0);reloadEx();}"
				     onClickRow="reloadEx"> 
					<@columns> 
						<@column name="ck" checkbox="true" />
						<@column name="username" title="登录名" formatter="editName" width="0.2" sortable="true" /> 
						<@column name="displayname" title="显示名" width="0.2" /> 
						<@column name="sex" title="性别" width="0.1" formatter="function(val, row){return val=='0'?'男':'女'}" />
						<@column name="mail" title="邮箱" width="0.2" /> 
						<@column name="tel" title="电话" width="0.2" /> 
						<@column name="id" hidden="true" /> 
					</@columns> 
				</@datatable>
			</div>
			<div region="east" iconCls="icon-reload" title="扩展信息" split="false"
				style="width: 200px">
				<a href="#" class="easyui-linkbutton" iconCls="icon-edit"
					plain="true" onclick="openExtCfg();">修改扩展信息</a>
				<table id="pg">
				</table>
			</div>
		</div>

	</div>

</div>

<script type="text/javascript">


	var emailEditor = {  
	        "type":"validatebox",  
	        "options":{  
	            "validType":"email"  
	        }};


	function reloadEx() {

		var row = $('#dg').datagrid('getSelected');
		$('#pg').propertygrid({
			url : '${root!}/frameuser/extable?userid=' + row.id,
			showGroup : true,
			scrollbarSize : 0,
			columns : [ [ {
				field : 'name',
				title : '属性',
				width : 100,
				sortable : true
			}, {
				field : 'value',
				title : '数据',
				width : 120,
				resizable : false
			} ] ]
		});
	}
	

	function addUser() {
		var node = $('#lefttree').tree('getSelected');
		var parent = "";
		if (node) {
			parent = node.id;
		}
		OpenDialogRefreshParent("${root!}/frameuser/add?parentId=" + parent, "", "500",
				"300");
	}

	function editUser(id_) {
		var id = id_ ? id_ : $('#dg').datagrid("getSelected").id;

		OpenDialogRefresh("${root!}/frameuser/edit/" + id, "", "500", "500");
	}

	function editName(val, row) {
		return '<a href="#" onclick="editUser(\'' + row.id + '\')">' + val
				+ '</a>';
	}

	function ResetPass() {
		var rows = $('#dg').datagrid("getChecked");
		if (rows.length == 0) {
			alert("请选择用户");
		} else {
			var ids = StringUtil.array2Str(rows, "id", ";");
			//alert(ids);
			$.ajax({
				url : "${root!}/frameuser/resetpass?ids=" + ids,
				type : "GET",
				success : function(msg) {
					alert(msg);
				}
			});
		}
	}

	function searchUser() {

		var username = $('#inpUsername').val();
		username = $.trim(username);
		var displayname = $('#inpDisplayname').val();
		displayname = $.trim(displayname);

		var node = $('#lefttree').tree("getSelected");
		var code = node ? node.attributes.deptCode : "";
		$('#dg').datagrid('reload', {
			username : username,
			displayname : displayname,
			deptcode : code
		});
	}

	function deleteUser() {
		var rows = $('#dg').datagrid("getChecked");
		if (rows.length == 0) {
			alert("请选择用户");
		} else {
			var ids = StringUtil.array2Str(rows, "id", ";");
			alert(ids);
			$.ajax({
				url : "${root!}/frameuser/delete?ids=" + ids,
				type : "GET",
				success : function(msg) {
					alert(msg);
					$('#dg').datagrid('reload'); //reload the user data
				}
			});
		}
	}

	function openExtCfg(){
		var row = $('#dg').datagrid('getSelected');
		OpenDialogRefresh("${root!}/frameuserconfig/extcfg?id="+row.id, "",800,500);
	}

</script>
</@center>
